<?php

class WebUser extends CWebUser
{

    protected $_model, $_curr_user;

    /**
     * 
     * @return boolean <b>TRUE</b> if current user is Admin
     */
    function isAdmin()
    {

        $user = $this->getCurrentUser();
        return ($user->type == Users::TYPE_ADMIN);
    }

    /**
     * 
     * @return boolean <b>TRUE</b> if current user is STAFF
     */
    function isStaff()
    {
        $user = $this->getCurrentUser();
        return ($user->type == Users::TYPE_STAFF);
    }

    /**
     * 
     * @return boolean <b>TRUE</b> if current user is Merchant
     */
    function isMerchant()
    {
        $user = $this->getCurrentUser();
        return ($user->type == Users::TYPE_BUSINESS AND $user->author_id == Users::SUPER_ADMIN);
    }

    function isBranch()
    {
        $user = $this->getCurrentUser();
        return ($user->type == Users::TYPE_BUSINESS AND $user->author_id != Users::SUPER_ADMIN );
    }

    function isConcierge()
    {
        $user = $this->getCurrentUser();
        return ($user->type == Users::TYPE_CONCIERGE);
    }

    /**
     * @return CActiveRecord Retrieve a single record of current user
     */
    function getCurrentUser()
    {
        if ($this->_curr_user == NULL)
        {
            $this->_curr_user = Users::model()->findByPk(Yii::app()->user->id);
        }

        return $this->_curr_user;
    }

    /**
     * @return CActiveRecord Retrieve a single record
     */

    /**
     * @param $id
     * @return Users/mixed
     */
    function getUserbyId($id)
    {

//        if ($this->_model === NULL)
//        {
        $this->_model = Users::model()->findByPk($id);
//        }

        return $this->_model;
    }

}
